<?php
/**
 * Created by PhpStorm.
 * User: ztos
 * Date: 2017/11/15
 * Time: 下午2:34
 */

namespace app\index\controller;

use app\common\model\Contact;
use think\Controller;
use app\common\model\PartyBuilding;
use think\Db;
use think\Request;
use app\common\model\Banner;

class News extends Controller
{
    /** 获取banner图
     * @return $this
     */
    public function getBanner()
    {
        $banner = new Banner();
        $map = ['status' => 0, 'banner' => 1];
        $res = $banner->where($map)->order('id asc')->limit(10)->select();

        return $res;
    }

    /**
     * 首页
     * @return mixed
     */
    public function index()
    {
        $banner = $this->getBanner();
        //return json_encode($banner);
        $this->assign('banner', $banner);

        return $this->fetch();
    }

    /**
     * 关于我们
     * @return mixed
     */
    public function about()
    {
        $banner = $this->getBanner();
        $this->assign('banner', $banner);
        return $this->fetch();
    }

    /**
     * 行业资讯
     * @return mixed
     */
    public function cases()
    {
        $product = new PartyBuilding();
        $map = ['type' => 2, 'status' => 1];
        $list = $product->where($map)->order('create_time desc')->paginate(8);
        $banner = $this->getBanner();
        $this->assign('banner', $banner);
        $this->assign('list', $list);

        return $this->fetch();
    }

    /**
     * 介绍
     * @return mixed
     */
    public function introduction()
    {
        $banner = $this->getBanner();
        $this->assign('banner', $banner);

        return $this->fetch();
    }

    /**
     * 产品服务
     * @return mixed
     */
    public function product()
    {
        $product = new PartyBuilding();
        $map = ['type' => 1, 'status' => 1];
        $list = $product->where($map)->order('create_time desc')->paginate(8);
        $banner = $this->getBanner();
        $this->assign('banner', $banner);
        $this->assign('list', $list);

        return $this->fetch();
    }

    /**
     * 服务
     * @return mixed
     */
    public function service()
    {
        $banner = $this->getBanner();
        $this->assign('banner', $banner);

        return $this->fetch();
    }

    /**
     * 联系我们
     * @return mixed
     */
    public function contact()
    {
        $banner = $this->getBanner();
        $contact = Contact::get(1);
        $this->assign('contact', $contact);
        $this->assign('banner', $banner);

        return $this->fetch();
    }

    /**
     * 详情
     * @return mixed
     */
    public function detail()
    {
        $id = input('id');
        $news = PartyBuilding::get($id);
        $this->assign("news", $news);

        return $this->fetch();
    }

    /**
     * 附件下载
     * @return mixed
     *
     */
    public function adjunct(){

        $list = Db::name('adjunct')->where(['status'=>0])->order('id  desc')->paginate(20);
        $this->assign("list", $list);
        return $this->fetch();
    }
}